package cn.lijida.weiwei.favor.modules.account.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.lijida.weiwei.favor.modules.account.entity.FavorAccount;
import cn.lijida.weiwei.favor.modules.account.mapper.FavorAccountMapper;
import cn.lijida.weiwei.favor.modules.account.service.IFavorAccountHomeService;
import cn.lijida.weiwei.favor.modules.account.service.IFavorAccountService;

/**
 * <p>
 * 账簿 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-12-28
 */
@Service
public class FavorAccountServiceImpl extends ServiceImpl<FavorAccountMapper, FavorAccount> implements IFavorAccountService {

	@Autowired
	private IFavorAccountHomeService accountHomeService;
	
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void create(FavorAccount account, Long loginId) throws Exception {
		account.setCreateMember(loginId);
		account.setCreateTime(new Date());
		
		boolean status = this.save(account);
		if(!status){
			throw new Exception("创建账簿失败");
		}
		
		//添加账簿家庭关系
		accountHomeService.join(account.getAccountId(),account.getCreateHome());
	}

}
